<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .father{
            width: 400px;
            height: 400px;
            margin: 100px;
            overflow: hidden;
            background-color: pink;
            position: relative;
        }
        .son{
            margin: 50px;
            top: 100px;
            width: 200px;
            height: 200px;
            background-color: purple;
            position: absolute;
            left: 10px;
            top: 10px;
        }
        .back{
            position: fixed;
            width: 50px;
            height: 50px;
            background-color: pink;
            right: 30px;
            bottom: 100px;
            display: none;
        }
        .container{
            width: 900px;
            height: 500px;
            background-color: skyblue;
            margin: 400px auto;
        }
    </style>
    <script src="jquery.min.js"></script>
</head>
<body>
    <div class="back">返回顶部</div>
    <div class="container"></div>
    <div class="father">
        <div class="son"></div>
    </div>
    <script>
        //offset()设置或获取元素偏移
        //offset()方法设置或返回被选元素相对于文档的偏移坐标、跟父级没有关系
        console.log($(".son").offset());

        //获取距离带有定位父级的偏移坐标position() 只能获取不能设置
        console.log($(".son").position());

        //设置获取元素被卷去的头部和左侧 scrollTop()/scrollLeft()
        $(window).scroll(function(){
            console.log($(document).scrollTop());
        })
    </script>
</body>
</html>